// pages/level/level.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    levelList: [{
        level: "优雅小虾",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level1.png",
        num:10
      },
      {
        level: "圣殿游侠",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level2.png",
        num:100
      },
      {
        level: "荣耀绅士",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level3.png",
        num:1000
      },
      {
        level: "尊贵诸侯",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level4.png",
        num:10000
      },{
        level: "枭雄霸王",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level5.png",
        num:50000
      },{
        level: "至尊皇帝",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level6.png",
        num:100000
      },{
        level: "永恒帝尊",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level7.png",
        num:500000
      },{
        level: "绝世无双",
        img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/level8.png",
        num:1000000
      },
    ],
    charmList: [{
      level: "见习艺人",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm1.png",
      num:10
    },
    {
      level: "小有名气",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm2.png",
      num:100
    },
    {
      level: "名声大振",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm3.png",
      num:1000
    },
    {
      level: "人气偶像",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm4.png",
      num:10000
    },{
      level: "闪耀之星",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm5.png",
      num:50000
    },{
      level: "光耀夺目",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm6.png",
      num:100000
    },{
      level: "风华绝代",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm7.png",
      num:500000
    },{
      level: "倾国倾城",
      img: "http://img.xunyinjiaoyou.com/static/xiaochengxu/level/charm8.png",
      num:1000000
    },
  ],
    levelShow:true,
    levelInfo: "",
    progressStyle: "",
    progressStylefixed:'position: absolute;top: 0;'
  },
  changerich(){
    this.setData({
      levelShow:true,
      progressStyle: this.data.progressStylefixed + "left:" + this.data.levelInfo.nextLevelPercent * 0.01 * 336 + "rpx"
    })
  },
  changecharm(){
    this.setData({
      levelShow:false,
      progressStyle: this.data.progressStylefixed + "left:" + this.data.levelInfo.nextCharmLevelPercent * 0.01 * 336 + "rpx"
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/user/levelpage",
      data: params
    }).then((res) => {
      console.log(res.data.result),
        this.setData({
          levelInfo: res.data.result,
          progressStyle: this.data.progressStylefixed + "left:" + res.data.result.nextLevelPercent * 0.01 * 336 + "rpx"
        })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})